#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

struct node {
	int w, v;
	node(int wi, int vi) {
		w = wi;
		v = vi;
	}
};

struct point {
	int w, id;
	point(int wi, int i) {
		w = wi;
		id = i;
	}
	bool operator < (const point x)const {
		return x.w < this->w;
	}
};

int n, m;
vector<node> G[305];
priority_queue<point> h;
bool S[305];

int main() {
	scanf("%d %d", &n, &m);
	int x, y, w;
	for (int i = 1; i <= m; ++i) {
		scanf("%d %d %d", &x, &y, &w);
		G[x].push_back(node(w, y));
		G[y].push_back(node(w, x));
	}
	
	int ans = 0;
	int index = 1;
	h.push(point(0, 1));
	while (index <= n) {
		int x = h.top().id, d = h.top().w;
		h.pop();
		if (S[x]) continue;
		S[x] = 1;
		++index;
		ans = max(ans, d);
		for (unsigned i = 0; i < G[x].size(); ++i) {
			int y = G[x][i].v, z = G[x][i].w;
			if (!S[y]) {
				h.push(point(z, y));
			}
		}
	}
	printf("%d %d\n", n - 1, ans);
	return 0;
}
